package com.osce.basic.controller;

import com.csce.domain.entity.basic.BasicExPlace;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.basic.IBasicExPlaceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考站表Controller
 *
 * @author zzx
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/basic/ex_place")
public class BasicExPlaceController extends BaseController {

    @Resource
    private IBasicExPlaceService basicExPlaceService;

    /**
     * 查询考站表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:ex_place:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicExPlace basicExPlace) {
        startPage();
        List<BasicExPlace> list = basicExPlaceService.selectBasicExPlaceList(basicExPlace);
        return getDataTable(list);
    }

    /**
     * 导出考站表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:ex_place:export')")
    @Log(title = "考站表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicExPlace basicExPlace) {
        List<BasicExPlace> list = basicExPlaceService.selectBasicExPlaceList(basicExPlace);
        ExcelUtil<BasicExPlace> util = new ExcelUtil<BasicExPlace>(BasicExPlace.class);
        util.exportExcel(response, list, "考站表数据");
    }

    /**
     * 获取考站表详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:ex_place:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basicExPlaceService.selectBasicExPlaceById(id));
    }

    /**
     * 新增考站表
     */
    @PreAuthorize("@ss.hasPermi('basic:ex_place:add')")
    @Log(title = "考站表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicExPlace basicExPlace) {
        return toAjax(basicExPlaceService.insertBasicExPlace(basicExPlace));
    }

    /**
     * 修改考站表
     */
    @PreAuthorize("@ss.hasPermi('basic:ex_place:edit')")
    @Log(title = "考站表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicExPlace basicExPlace) {
        return toAjax(basicExPlaceService.updateBasicExPlace(basicExPlace));
    }

    /**
     * 删除考站表
     */
    @PreAuthorize("@ss.hasPermi('basic:ex_place:remove')")
    @Log(title = "考站表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basicExPlaceService.deleteBasicExPlaceByIds(ids));
    }
}
